package com.liangzhong.proxy.notice
{
	import com.common.utils.Debug;
	import com.liangzhong.commandconst.bag.SMDBag;
	import com.liangzhong.commandconst.notice.SMDNotice;
	import com.liangzhong.constants.NotificationConstants;
	import com.liangzhong.manager.TimerManager;
	import com.liangzhong.proxy.BaseProxy;
	import com.socket.clientsocket.IClientSocket;
	
	import flash.utils.ByteArray;

	/**
	 * 公告 
	 * @author Administrator
	 * 
	 */	
	public class NoticeProxy extends BaseProxy
	{
		/**
		 *俱乐部proxy名字 
		 */
		public static const PROXYNAME:String = "notice_proxyname";
		/**
		 * [lv,showTime,type,playerName,goodsName]
		 */
		public static const GET_NOTIC:String = "get_notic";
		public static const ACHIEVEMENT:String = "get_achievement6666666";
		public function NoticeProxy(proxyName:String=null, data:Object=null)
		{
			super(proxyName, data);
//			TimerManager.getInstance().registerTimer("",10000,0,test);
//			TimerManager.getInstance().registerTimer("achi",10000,1,achievement);
		}
		
		override public function onSocketRead(mainCmdID:uint, subCmdID:uint, buffer:ByteArray, dataSize:int, clientSocket:IClientSocket):Boolean
		{
			
			switch(mainCmdID)
			{
				case SMDNotice.MAIN://成就
					return	onDeal(mainCmdID,subCmdID,buffer,dataSize);
			}
			return false;
		}
		private function onDeal(mainCmdID:uint,
								subCmdID:uint,
								buffer:ByteArray, 
								dataSize:int):Boolean
		{
			var pid:int;
			var type:int;
			var number:int;
			switch(subCmdID)
			{	
				case SMDNotice.SYSTEMNOTICE://系统公告
//					this.sendNotification(GET_NOTIC,{});
					getNoticeData(buffer);
					return true;
				case SMDNotice.ACHIEVEMENT://成就
//					pid = buffer.readShort();
//					this.sendNotification(ACHIEVEMENT,pid);
					return true;
				
				
			}
			return false;
		}
		
		/**
		 * 获得公告数据 
		 * @param buffer
		 * 
		 */
		private function getNoticeData(buffer:ByteArray):void
		{
			var lv:int = buffer.readByte();//等级
			var time:int = buffer.readByte();//显示次数
			var showTime:int = buffer.readShort();//显示时间
			var type:int = buffer.readShort();//类型
			var playerName:String;
			var goodsName:String;
			var len:int;
			var str:String ;
			switch(type)
			{
				case 1:
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
					break;
				case 2://获得了红卡
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
					len = buffer.readShort();
					goodsName = buffer.readUTFBytes(len);
//					str = playerName + "通过球员探索功能获取了" + goodsName;
					break;
				case 3://获得黑
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
					len = buffer.readShort();
					goodsName = buffer.readUTFBytes(len);
//					str = playerName + "通过球员探索功能获取了" + goodsName;
					break;
				case 4://登上S级别！
					
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
//					str = playerName + "通过不懈努力，登上"+"<font color = '#cc00cc' > S</font>"+"级别！" ;
					break;
				case 5://XXX已经通过了S级巡回赛！称霸世界的梦想跨进了一大步
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
//					str = playerName + "已经通过了S级巡回赛！称霸世界的梦想跨进了一大步" ;
					break;
				case 6://冲级达人XXX已经冲到50级！成为了第一阶梯的球队！
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
//					str = "冲级达人"+playerName + "已经冲到50级！成为了第一阶梯的球队！" ;
					break;
				case 7://合成属性卡XXX的运气爆发了！！合成了一张XXXXX
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
					len = buffer.readShort();
					goodsName = buffer.readUTFBytes(len);
//					str = playerName + "运气爆发了！！合成了一张" + goodsName;
					break;
				case 8://地球人已经没法阻止XXXX了！他已经成为了黑色球员！！
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
//					str = "地球人已经没法阻止"+ playerName + "了！他已经成为了黑色球员！！" ;
					break;
				case 9://XXXX获得了一张黑色洗炼卡！黑色球员就要诞生了吗！？？？？
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
//					str =  playerName + "获得了一张黑色洗炼卡！黑色球员就要诞生了吗！？？？？" ;
					break;
				case 10://洗练出红色球员
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
//					str =  "新一代天皇巨星的诞生！"+playerName + "已经是红色球员了！" ;
					
					break;
				case 11://获得红色洗炼卡
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
//					str =  playerName + "获得了一张红色洗炼卡！红色球员近在咫尺！" ;
					break;
				case 12://玩家通过球员探索功能获取橙色球员
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
					len = buffer.readShort();
					goodsName = buffer.readUTFBytes(len);
//					str =  playerName + "通过球员探索功能获取了" + goodsName;
					break;
				case 13://玩家通过球员荣誉抽奖获取橙色球员包
					len = buffer.readShort();
					playerName = buffer.readUTFBytes(len);
//					str = playerName+"在天梯赛默默耕耘，荣誉抽取了一个橙色球员包！";
					break;
				case 14:
				case 15:
				case 100:
					playerName = buffer.readUTF();
//					playerName = buffer.readObject();
//					len = buffer.readShort();
//					playerName = buffer.readUTFBytes(len);
					break;
			}
			var arr:Array = [];
			for(var i:int = 0;i < time;i++)
			{
				arr.push([lv,showTime,type,playerName,goodsName]);//[lv,showTime,type,playerName,goodsName]
			}
			
			
			this.sendNotification(GET_NOTIC,{array:arr});
		}
		
		/**
		 * 球员颜色值 
		 * @return 
		 * 
		 */
		private function getPlayerColour():uint
		{
			
			return 0xFF00FF;
		}
		
		
//		private function test($value:*):void
//		{
////			this.sendNotification(GET_NOTIC,{});
//			this.sendNotification(GET_NOTIC,{array:[[1,1,1,"<font color= '#FF00FF'>在天梯赛默默耕耘，荣誉抽取了一个橙色球员包！</font>"],
//				[1,1,1,"获得了一张红色洗炼卡！红色球员近在咫尺！"],
//				[1,1,1,"获得了一张黑色洗炼卡！黑色球员就要诞生了吗！？？？？"]]});
//			TimerManager.getInstance().registerTimer("achi",40000,0,achievement);
//		}
		/**
		 * 测试 
		 * @param $value
		 * 
		 */
		private function test($value:*):void
		{
//			this.sendNotification(ACHIEVEMENT,{});
			var playerName:String;
			var goodsName:String;
			var type:int = Math.ceil(Math.random() * 14)
			switch(type)
			{
				case 1:
					playerName = "长度"
					break;
				case 2://获得了红卡
					playerName = "红卡"
					goodsName = "获得红卡了"
					break;
				case 3://获得黑
					playerName = "黑卡"
					goodsName = "获得黑卡了"
					break;
				case 4://登上S级别！
					playerName = "S级"
					goodsName = "到达S级"
					break;
				case 5://XXX已经通过了S级巡回赛！称霸世界的梦想跨进了一大步
					playerName = "巡回赛"
					goodsName = "S"
					break;
				case 6://冲级达人XXX已经冲到50级！成为了第一阶梯的球队！
					playerName = "冲到50级"
					goodsName = "50"
					break;
				case 7://合成属性卡XXX的运气爆发了！！合成了一张XXXXX
					playerName = "合成属性卡"
					goodsName = "XXX";
					break;
				case 8://地球人已经没法阻止XXXX了！他已经成为了黑色球员！！
					playerName = "黑色球员"
					goodsName = "黑色球员";
					break;
				case 9://XXXX获得了一张黑色洗炼卡！黑色球员就要诞生了吗！？？？？
					playerName = "黑色洗炼卡"
					goodsName = "黑色洗炼卡";
					break;
				case 10://洗练出红色球员
					playerName = "红色球员"
					goodsName = "红色球员";					
					break;
				case 11://获得红色洗炼卡
					playerName = "获得红色洗炼卡"
					goodsName = "获得红色洗炼卡";
					break;
				case 12://玩家通过球员探索功能获取橙色球员
					playerName = "橙色球员"
					goodsName = "橙色球员";
					break;
				case 13://玩家通过球员荣誉抽奖获取橙色球员包
					playerName = "橙色球员包"
					goodsName = "橙色球员包";
					break;
			}
			var arr:Array = [];
			arr.push([1,10,type,playerName,goodsName]);
			this.sendNotification(GET_NOTIC,{array:arr});
		}
	}
}